package tw.ds0218.widgets.reporttime;

import java.util.ArrayList;

import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class ReportTimeBroadcastReceiver extends BroadcastReceiver {
	// log tag
    private static final String TAG = "ReportTime";
    
	@Override
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, TAG+"_BR_onReceive", Toast.LENGTH_SHORT).show();

        // For our example, we'll also update all of the widgets when the timezone
        // changes, or the user or network sets the time.
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)
                || action.equals(Intent.ACTION_TIME_CHANGED)) {
            AppWidgetManager gm = AppWidgetManager.getInstance(context);
            ArrayList<Integer> appWidgetIds = new ArrayList<Integer>();
            ArrayList<String> texts = new ArrayList<String>();

            //AVtokei.loadAllTitlePrefs(context, appWidgetIds, texts);
            System.out.println("==========Broadcast======");
            final int N = appWidgetIds.size();
            for (int i=0; i<N; i++) {
            	ReportTime.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i));
            }
        }

	}

}
